layui.use(['layer', 'form', 'jquery', 'getUrlParas'], function () {

    document.querySelector('#formLogin').addEventListener('submit', function (e) {
        e.preventDefault();
    }, false);

    var layer = layui.layer,
        form = layui.form(),
        $ = layui.jquery,
        getUrlParas = layui.getUrlParas;

    var redirect = getUrlParas('redirect');
    if(redirect===null){
        location.href="/login";
    }else{
        document.getElementById('inputHidden').value=redirect;
    }

    form.on('submit(buttonSubmit)', function (data) {
        $.ajax({
            method: 'GET',
            url:'/cas/doLogin',
            data: data.field,
            dataType:'jsonp',
            jsonp:'callback',
            jsonpCallback:'returnjs',
            crossDomain:true,
            success: function (json) {
                var url=json.redirect;
                // var url=decodeURI(json.redirect)
                if (json.status) {
                    location.href=url;
                } else {
                    layer.msg('登录失败!');
                }
            },
            error: function () {
                layer.msg('网络错误!');
            }
        });
        return false;
    });
});
